﻿Imports SIRData
Public Class frmEmpleadoListado

  Private m_bKey As Boolean = False
  Private m_siCodEmp As Int16 = 0
  Private m_vNomEmp As String = String.Empty
  Private m_bSelected As Boolean = False

  Public Property osiCodEmp() As Int16
    Get
      Return m_siCodEmp
    End Get
    Set(ByVal value As Int16)
      m_siCodEmp = value
    End Set
  End Property

  Public Property ovNomEmp() As String
    Get
      Return m_vNomEmp
    End Get
    Set(ByVal value As String)
      m_vNomEmp = value
    End Set
  End Property

  Public Property bSelected() As Boolean
    Get
      Return m_bSelected
    End Get
    Set(ByVal value As Boolean)
      m_bSelected = value
    End Set
  End Property


  Private Sub frmEmpleadoListado_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Try
      Call ListarEmpleados()
      m_bKey = True

    Catch ex As Exception
      MessageBox.Show(ex.Message, g_sModulo, MessageBoxButtons.OK, MessageBoxIcon.Error)
    Finally
      GC.Collect()
    End Try
  End Sub

  Private Sub ListarEmpleados()
    Dim m_Empleado As New clsEmpleado(g_sConnectString)
    Try

      If m_bKey Then
        dgvListado.DataSource = m_Empleado.EmpleadoListar(txtvNomEmp.Text.Trim)
      Else
        dgvListado.DataSource = m_Empleado.EmpleadoListar()
      End If


    Catch ex As Exception
      Throw New Exception(ex.Message)
    Finally
      m_Empleado = Nothing
      GC.Collect()
    End Try
  End Sub

  Private Sub btnFiltrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFiltrar.Click
    Try
      Call ListarEmpleados()

    Catch ex As Exception
      MessageBox.Show(ex.Message, g_sModulo, MessageBoxButtons.OK, MessageBoxIcon.Error)
    Finally
      GC.Collect()
    End Try
  End Sub

  Private Sub btnSeleccionar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeleccionar.Click
    Try
      Call SeleccionarEmpleado()

    Catch ex As Exception
      MessageBox.Show(ex.Message, g_sModulo, MessageBoxButtons.OK, MessageBoxIcon.Error)
    Finally
      GC.Collect()
    End Try
  End Sub

  Private Sub dgvListado_RowPrePaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles dgvListado.RowPrePaint
    Try
      dgvListado.Rows(e.RowIndex).DefaultCellStyle.BackColor = IIf(e.RowIndex Mod 2 = 0, Color.Honeydew, Color.White)
      dgvListado.Rows(e.RowIndex).DefaultCellStyle.Font = New Font("Lucida Sans", 8)
    Catch ex As Exception
      MessageBox.Show(ex.Message, g_sModulo, MessageBoxButtons.OK, MessageBoxIcon.Error)
    Finally
      GC.Collect()
    End Try
  End Sub

  Private Sub dgvListado_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvListado.CellDoubleClick
    Try
      Call SeleccionarEmpleado()

    Catch ex As Exception
      MessageBox.Show(ex.Message, g_sModulo, MessageBoxButtons.OK, MessageBoxIcon.Error)
    Finally
      GC.Collect()
    End Try
  End Sub

  Private Sub SeleccionarEmpleado()
    Try
      m_bSelected = True
      m_siCodEmp = dgvListado.Item("siCodEmp", dgvListado.CurrentCell.RowIndex).Value
      m_vNomEmp = dgvListado.Item("vNomEmp", dgvListado.CurrentCell.RowIndex).Value
      Me.Close()

    Catch ex As Exception
      Throw New Exception(ex.Message)
    Finally
      GC.Collect()
    End Try
  End Sub
End Class